﻿using HamcoWcs.Entitys.Bases;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace HamcoWcs.Entitys.Logss
{
    public class CommunicationLog : AuditEntity, IEntityTypeConfiguration<CommunicationLog>
    {
        public string TransactionId { get; set; }

        public string Direction { get; set; }

        public string MessageType { get; set; }

        public string MessageName { get; set; }

        public string MessageStatus { get; set; }

        public string Content { get; set; }

        public string Return { get; set; }

        public string UnitId { get; set; }

        public string Sender { get; set; }

        public string Receiver { get; set; }


        public CommunicationLog()
        {

        }

        public CommunicationLog(string direction)
        {
            Direction = direction;
        }


        public void Configure(EntityTypeBuilder<CommunicationLog> builder)
        {
            builder.HasComment("消息日志");
            builder.Property(x => x.TransactionId).IsRequired().HasMaxLength(40).HasComment("消息号");
            builder.Property(x => x.Direction).IsRequired().HasMaxLength(20).HasComment("ex:WCS > MES | WCS < MES");
            builder.Property(x => x.MessageType).HasDefaultValue("").HasMaxLength(30).HasComment("消息类型");
            builder.Property(x => x.MessageName).IsRequired().HasMaxLength(50).HasComment("消息名称");
            builder.Property(x => x.Content).IsRequired().HasColumnType("longtext").HasComment("数据内容");
            builder.Property(x => x.Return).IsRequired().HasColumnType("longtext").HasComment("返回的数据");
            builder.Property(x => x.MessageStatus).HasDefaultValue("").HasMaxLength(20).HasComment("消息状态");
            builder.Property(x => x.UnitId).HasDefaultValue("").HasMaxLength(30).HasComment("托盘号");
            builder.Property(x => x.Sender).HasDefaultValue("").HasMaxLength(30).HasComment("发送者");
            builder.Property(x => x.Receiver).HasDefaultValue("").HasMaxLength(30).HasComment("接收者");

            builder.HasIndex(x => x.TransactionId).IsUnique();
        }
    }
}
